package com.tgy.reflection;

/***
 * @ClassName: TestReflection1
 * @Description: 学习反射相关代码
 * @Auther: 送一一块二向箔
 * @Date: 11:42 2021/12/1
 * @version : V1.0
 */
public class TestReflection1 {
    public static void main(String[] args) {
        //通过反射获取类的Class对象
        try {
            Class<?> c1 = Class.forName("com.tgy.reflection.User");
            Class<?> c2 = Class.forName("com.tgy.reflection.User");
            Class<?> c3 = Class.forName("com.tgy.reflection.User");

            System.out.println(c1);
            System.out.println(c1.getName());

            //一个类在内存中只有一个Class对象
            //一个类被加载后，类的整个结构都会被封装在Class对象中
            System.out.println(c1.hashCode());
            System.out.println(c2.hashCode());
            System.out.println(c3.hashCode());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

class User{
    private String name;
    private int age;
    private int id;

    private void test1(){

    }

    public User(String name, int age, int id) {
        this.name = name;
        this.age = age;
        this.id = id;
    }

    //实体类 pojo entity
    public User() {
    }

    public String getName() {
        return name;
    }

    public User setName(String name) {
        this.name = name;
        return this;
    }

    public int getAge() {
        return age;
    }

    public User setAge(int age) {
        this.age = age;
        return this;
    }

    public int getId() {
        return id;
    }

    public User setId(int id) {
        this.id = id;
        return this;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                '}';
    }
}
